import os

from jinja2 import Template


def render(input_file, output_file):
    """模板填充"""

    with open(input_file, encoding='utf_8') as input_fd, \
            open(output_file, mode='w', encoding='utf_8') as output_fd:

        server_url = 'http://127.0.0.1:5005'
        channel = '/socket.io/'
        print("html server Will connect to: {}".format(server_url))
        print("html channel: {}".format(channel))

        # 模板填充
        template = Template(input_fd.read())
        rendered_string = template.render(server_url=server_url, channel=channel)

        output_fd.write(rendered_string)


if __name__ == "__main__":
    index_html_tpl = "./index/index.html.tpl"
    index_html = "./index/index.html"
    render(index_html_tpl, index_html)
